Use case: IRDA receive in interrupt mode

This use case shows how to receive IRDA data in interrupt mode. In HAL2, IRDA support is handled via the HAL UART driver.

Sequence diagram

    @startuml
    participant "Application" as p1
    participant "HAL IRDA driver" as p2
    participant "IRDAX_IRQHandler" as p3

    == initialization and configuration ==
    == IRDA HAL Receive IT ==

    p1->p2: <color: green> HAL_IRDA_Receive_IT(&hirda,  aRxBuffer, DATA_TO_RECEIVE_SIZE)
    note over p2 #00FF00
    Receiving data ongoing
    end note
    p2-->p1: HAL_OK
    p3<-: IRDAX data interrupt
    p3->p2: HAL_IRDA_IRQHandler
    note over p2 #FFFF99
    All data (Size == hirda->RxXferCount) have been received
    end note
    note over p2 #00FF00
    End of receiving data
    end note
    p2->p1: HAL_IRDA_RxCpltCallback(hirda->RxXferCount)

    @enduml

Code snippet

HAL1

HAL2

#define DATA_TO_RECEIVE_SIZE        256

uint8_t aRxBuffer[DATA_TO_RECEIVE_SIZE];

IRDA_HandleTypeDef hirda;

/* Optional: register receive-complete callback */
HAL_IRDA_RegisterCallback(&hirda, HAL_IRDA_RX_CB_ID, IRDA_RxCpltCallback);

/* Start receive in interrupt mode */
(void)HAL_IRDA_Receive_IT(&hirda, aRxBuffer, DATA_TO_RECEIVE_SIZE);
#define DATA_TO_RECEIVE_SIZE        256

uint8_t aRxBuffer[DATA_TO_RECEIVE_SIZE];

hal_uart_handle_t huart;

/* Optional: register receive-complete callback */
HAL_UART_RegisterRxCpltCallback(&huart, UART_RxCpltCallback);

/* Start receive in interrupt mode */
(void)HAL_UART_Receive_IT(&huart, aRxBuffer, DATA_TO_RECEIVE_SIZE);

Key changes

  1. HAL2 uses the UART driver (HAL_UART_Receive_IT() + HAL_UART_IRQHandler()) instead of IRDA-specific APIs.